package com.recipedb.recipedb.controller;

import com.recipedb.recipedb.entity.RecipeTag;
import com.recipedb.recipedb.entity.RecipeTagId;
import com.recipedb.recipedb.service.RecipeTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/recipetag")
public class RecipeTagController {

    @Autowired
    private RecipeTagService service;

    @PostMapping
    public RecipeTag add(@RequestBody RecipeTag entity) {
        return service.save(entity);
    }

    @DeleteMapping
    public void delete(@RequestBody RecipeTagId id) {
        service.deleteById(id);
    }

    @GetMapping("/single")
    public Optional<RecipeTag> get(@RequestBody RecipeTagId id) {
        return service.findById(id);
    }

    @GetMapping("/all")
    public List<RecipeTag> getAll() {
        return service.findAll();
    }
}
